package pm.oo.util;

import com.sun.star.comp.helper.BootstrapException;

/**
 * support ONE singleton uno connection to an running office installation!
 * Can be used to open/use/close connection to uno environment of an office. If
 * necessary a new office instance is started.
 */
public class OfficeConnection {

    private static com.sun.star.uno.XComponentContext officeContext;

    public static synchronized void createConnection() throws BootstrapException {
        if (officeContext == null) {
            officeContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
        }
    }

    public static synchronized void disconnect() {
        if (officeContext != null) {
            officeContext = null;
        }
    }

    private OfficeConnection() {
    }

    /**
     * returns remote component context of the connected office
     */
    public static synchronized com.sun.star.uno.XComponentContext getOfficeContext() {
        return officeContext;
	}
}

